import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Login from '../views/wang/Login.vue'
import chen from './chen/index'
import liao from './liao/index'
import liu from './liu/index'
import tian from './tian/index'
import wang from './wang/index'
import zhou from './zhou/index'
import zeng from './zeng/index'
let cityOrDistrict = ''
const routerToLink = function () {
  const allview = localStorage.getItem('userAuthority')
  if (allview == 'city') {
    cityOrDistrict = '/Disease'
  }
  else {
    cityOrDistrict = '/AllView'
  }
  return cityOrDistrict
}
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'default',
    component: Login
  },
  {
    path: '/Home',
    name: 'Home',
    component: () => import('@/views/Home.vue'),
    redirect: () => { return routerToLink() },
    children: [
      {
        path: '/AllView',
        name: 'AllView',
        component: () => import('@/views/wang/AllView.vue'),
      },
      {
        path: '/Disease',
        name: 'Disease',
        component: () => import('@/views/wang/Disease/AllView.vue')
      },
      ...chen, ...liao, ...liu, ...tian, ...wang, ...zhou, ...zeng
    ]

  }



]

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
})

// 拦截
// router.beforeEach((to: any, from: any, next: any) => {
//   if (to.path == '/') {
//     next()
//   }
//   // 获取token
//   const token = localStorage.getItem('token')
//   if (!token) {
//     next('/')
//   } else {
//     next()

//   }

// })




export default router
